package net.sunofbeaches.dao;

import net.sunofbeaches.pojo.Article;
import net.sunofbeaches.pojo.ArticleNoContent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ArticleNoContentDao extends JpaRepository<ArticleNoContent, String>, JpaSpecificationExecutor<ArticleNoContent> {
    ArticleNoContent findOneById(String articleId);

    @Query(nativeQuery = true, value = "SELECT * FROM `tb_article` WHERE `labels` LIKE ?1 AND `id` != ?2 LIMIT ?3")
    List<ArticleNoContent> listArticleByLikeLabel(String targetLabel, String articleId, int size);

    /**
     * 用sql语句排除推挤外鱼推荐重复的
     * TODO ： SELECT * FROM `tb_article`
     *         WHERE `id` NOt IN (SELECT id FROM `tb_article`
     *         WHERE `labels` LIKE '%java%' AND `id` != '909820945607680512')
     *
     * @param articleId
     * @param dxSize
     * @return
     */
    @Query(nativeQuery = true, value = "SELECT * FROM `tb_article` WHERE `id` != ? ORDER BY `create_time` DESC LIMIT ?")
    List<ArticleNoContent> listArticleByLikeLabel(String articleId, int dxSize);
}
